class Solution {
    int ret;
    int target;

    public int findTargetSumWays(int[] nums, int _target) {
        target = _target;
        dfs(nums, 0, 0);
        return ret;
    }

    public void dfs(int[] nums, int pos, int path) {
        if (pos == nums.length) {
            if (path == target) {
                ret++;
            }
            return;
        }
        // 两种选择
        dfs(nums, pos + 1, path + nums[pos]);
        dfs(nums, pos + 1, path - nums[pos]);
    }
}